/*
 * Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.jinbooks.persistence.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinbooks.entity.channel.Partner;
import com.jinbooks.entity.channel.dto.PartnerPageDto;
import com.jinbooks.persistence.mapper.PartnerMapper;
import com.jinbooks.persistence.service.PartnerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 渠道/合作方 Service实现类
 *
 * @author your-name
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PartnerServiceImpl extends ServiceImpl<PartnerMapper, Partner> implements PartnerService {

    private final PartnerMapper baseMapper;

    @Override
    public Page<Partner> pageList(PartnerPageDto dto) {
        return baseMapper.pageList(dto.build(), dto);
    }
    
    @Override
    public Partner getById(String id) {
        return baseMapper.selectById(id);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(Partner partner) {
        return baseMapper.insert(partner) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(Partner partner) {
        return baseMapper.updateById(partner) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeById(String id) {
        return baseMapper.deleteById(id) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByIds(List<String> ids) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}